#!coding=utf-8
from django.db import models
import settings, datetime
from enterprise_basic_information.models import Enterprise,Application_status
# Create your models here.

#主要产品(含副产品和中间体)及输出
"""
不用了
"""
class Chemicals(models.Model):
    name = models.CharField(u'化学品名称', max_length=50)
    category = models.CharField(u'类别', max_length=50)
    cas = models.CharField(u'cas', max_length=50)
    is_dangerous = models.CharField(u'是否危险化学品', max_length=10)
    is_emphasis = models.CharField(u'是否重点环境管理危险品', max_length=10)
    is_re_danger = models.CharField(u'是否属于安监重点', max_length=50)
    physical_form = models.CharField(u'物质形态', max_length=50)
    hazard_pro = models.CharField(u'危害特性', max_length=50)
    actual_amount = models.CharField(u'实际产量', max_length=50)
    storage_mode = models.CharField(u'存储方式', max_length=50)
    max_sto_amount = models.CharField(u'生产最大存量', max_length=50)
    max_input_amount = models.CharField(u'储存最大存量', max_length=50)
    out_mode = models.CharField(u'输出方式',max_length=50)
    out_where = models.CharField(u'输出去向',max_length=50)
    add_time = models.DateTimeField(u'添加时间', default=datetime.datetime.now())
    enterprise = models.ForeignKey(Enterprise)

#原辅材料输入及使用
"""
2
"""
class Materials(models.Model):
    product_id = models.CharField(u'产品编号', max_length=50)
    number = models.CharField(u'原辅料编号', max_length=50)
    name = models.CharField(u'原辅料名称', max_length=50)
    chemicals_name = models.CharField(u'化学品名称', max_length=50)
    cas = models.CharField(u'cas', max_length=50)
    is_dangerous = models.CharField(u'是否危险化学品', max_length=10)
    is_emphasis = models.CharField(u'是否重点环境管理危险品', max_length=10)
    physical_form = models.CharField(u'物质形态', max_length=50)
    hazard_pro = models.CharField(u'危害特性', max_length=50)
    input_amount = models.CharField(u'使用量', max_length=50)
    source = models.CharField(u'来源', max_length=100)
    input_mode = models.CharField(u'输入方式', max_length=50)
    usage_amount = models.CharField(u'循环使用量', max_length=50)
    storage_mode = models.CharField(u'存储方式', max_length=50)
    max_sto_amount = models.CharField(u'生产最大存量', max_length=50)
    max_input_amount = models.CharField(u'储存最大存量', max_length=50)
    add_time = models.DateTimeField(u'添加时间', default=datetime.datetime.now())
    app_status = models.ForeignKey(Application_status, null=True)
    submit_type = models.IntegerField(u'确认状态', max_length=13)
    enterprise = models.ForeignKey(Enterprise)


"""
4
"""
#产品信息表
class Product(models.Model):
    name = models.CharField(u'产品名称', max_length=50)
    sid = models.CharField(u'产品编号', max_length=50)
    other_name = models.CharField(u'其他名称', max_length=50)
    cas = models.CharField(u'化学文摘号(cas)', max_length=50)
    category = models.CharField(u'产品类别名称', max_length=50)
    category_code = models.CharField(u'产品类别代码', max_length=50)
    his_max_amount = models.CharField(u'历史最大产量', max_length=50)
    year_amount = models.CharField(u'年产量', max_length=50)
    domestic_sales_amount = models.CharField(u'国内产量', max_length=50)
    exports_amount = models.CharField(u'出口量', max_length=50)
    storage_amount = models.CharField(u'调查存储量', max_length=50)
    is_dangerous = models.CharField(u'是否危险化学品', max_length=10)
    is_emphasis = models.CharField(u'是否重点环境管理危险品', max_length=10)
    is_re_danger = models.CharField(u'是否属于安监重点', max_length=50)
    physical_form = models.CharField(u'物质形态', max_length=50)
    use_code = models.CharField(u'用途代码',max_length=50)
    hazard_pro = models.CharField(u'危害特性', max_length=50)
    actual_amount = models.CharField(u'实际产量', max_length=50)
    storage_mode = models.CharField(u'存储方式', max_length=50)
    max_sto_amount = models.CharField(u'生产最大存量', max_length=50)
    max_input_amount = models.CharField(u'储存最大存量', max_length=50)
    out_mode = models.CharField(u'输出方式',max_length=50)
    out_where = models.CharField(u'输出去向',max_length=50)
    add_time = models.DateTimeField(u'添加时间', default=datetime.datetime.now())
    app_status = models.ForeignKey(Application_status, null=True)
    submit_type = models.IntegerField(u'确认状态', max_length=13)
    enterprise = models.ForeignKey(Enterprise)

"""
3
"""
#中间产品信息
class InterMeditatesPro(models.Model):
    name = models.CharField(u'中间产品化学品名称', max_length=50)
    pro_name = models.CharField(u'商品名称', max_length=50)
    other_name = models.CharField(u'别名', max_length=50)
    cas = models.CharField(u'cas', max_length=50)
    physical_form = models.CharField(u'物质形态', max_length=50)
    is_dangerous = models.CharField(u'是否危险化学品', max_length=10)
    is_emphasis = models.CharField(u'是否重点环境管理危险品', max_length=10)
    year_amount = models.CharField(u'年产量', max_length=50)
    storage_mode = models.CharField(u'存储方式', max_length=50)
    max_sto_amount = models.CharField(u'生产最大存量', max_length=50)
    max_input_amount = models.CharField(u'储存最大存量', max_length=50)
    add_time = models.DateTimeField(u'添加时间', default=datetime.datetime.now())
    app_status = models.ForeignKey(Application_status, null=True)
    submit_type = models.IntegerField(u'确认状态', max_length=13)
    enterprise = models.ForeignKey(Enterprise)

#产品成分分类表
class IngredientsType(models.Model):

    """原辅料，
    """
    name = models.CharField(u'成分分类名称', max_length=20)

#化学物质信息
class Ingredients(models.Model):
    e_name = models.CharField(u'化学名称', max_length=50)
    e_code = models.CharField(u'化学品临时编码', max_length=50)
    e_struct = models.CharField(u'结构式', max_length=50)
    e_molecular_formula = models.CharField(u'分子式', max_length=100)
    e_is_dangerous = models.CharField(u'是否危险化学品', max_length=50)
    e_is_emphasis = models.CharField(u'是否重点环境管理危险品', max_length=10)
    e_other_name = models.CharField(u'其他名称', max_length=50)
    e_amount = models.CharField(u'含量', max_length=50)
    e_shechun = models.CharField(u'成分折纯量(吨/年)', max_length=50)
    app_status = models.ForeignKey(Application_status, null=True)

    def getBelongstoParent(self):
        return ChemicalsRelative.objects.get(igds_entity=self)

    def getParentType(self):
        return ChemicalsRelative.objects.get(igds_entity=self).cr_type.name
"""
化学物质信息
"""
class ChemicalsRelative(models.Model):
    cr_type = models.ForeignKey(IngredientsType)

    """
    （原辅料对应的ID）
    """
    che_entity = models.IntegerField(u'具体化学品表中唯一标识',max_length=11)
    igds_entity = models.ForeignKey(Ingredients)
